Skip to content

feat: add idle state handling to movement state logic - #382

Merged
AngeloTadeucci merged 1 commit into
masterfrom
npc-spawn
Mar 25, 2025
Merged

feat: add idle state handling to movement state logic#382
AngeloTadeucci merged 1 commit into
masterfrom
npc-spawn

Conversation

@AngeloTadeucci

@AngeloTadeucci AngeloTadeucci commented Mar 25, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Enhanced idle state handling for smoother and more responsive character animations.
    • Improved animation logic to accurately detect and process idle sequences, resulting in more natural transitions and expressive behaviors for NPCs and actors.

@coderabbitai

coderabbitai Bot commented Mar 25, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This update implements explicit handling for the actor's idle state. In the MovementState class, the idle state is now processed in both the KeyframeEvent and Update methods through new case branches. The logic in the Emote method has been reversed to correctly assign the idle state when appropriate. Additionally, the FieldNpc class’s Animate method now dynamically determines if an animation is idle by checking the sequence name, replacing a hardcoded value. No public API declarations were altered.

Changes

File(s) Change Summary
Maple2.Server.Game/.../MovementState.cs Added handling for ActorState.Idle in KeyframeEvent (calling StateEmoteEvent) and in Update (calling EmoteStateUpdate).
Maple2.Server.Game/.../MovementState.EmoteTask.cs Reversed the logic in the Emote method to set the actor’s state to Idle when isIdle is true, and to Emotion otherwise.
Maple2.Server.Game/.../FieldNpc.cs Updated Animate to compute an isIdle flag by checking if sequenceName contains "idle" (case-insensitive) and pass it to TryEmote instead of a hardcoded false.

Sequence Diagram(s)

sequenceDiagram
  participant C as Client
  participant MS as MovementState
  participant ET as EmoteTask

  C->>MS: Call KeyframeEvent(keyName)
  alt ActorState.Idle
    MS->>MS: Call StateEmoteEvent(keyName)
  else Other State
    MS->>MS: Process other state event
  end

  C->>MS: Call Update(tickCount, tickDelta)
  alt ActorState.Idle
    MS->>MS: Call EmoteStateUpdate(tickCount, tickDelta)
  end

  C->>ET: Call Emote(isIdle)
  alt isIdle true
    ET->>ET: Set actor state to Idle
  else isIdle false
    ET->>ET: Set actor state to Emotion
  end
Loading
sequenceDiagram
  participant NPC as FieldNpc
  participant MS as MovementState

  NPC->>NPC: Animate(sequenceName)
  NPC->>NPC: Check for "idle" in sequenceName
  NPC->>MS: Call TryEmote(isIdle)
Loading

Suggested reviewers

  • Zintixx

Poem

I'm a bunny coding in a field of bytes,
Hopping through idle states in the nights.
With every change in tick and call,
I dance in the code—a joyful ball.
Carrots and code, in perfect delight,
Celebrating changes with a bunny's light!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a126b08 and d8193b0.

📒 Files selected for processing (3)
  • Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementState.cs (2 hunks)
  • Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateTasks/MovementState.EmoteTask.cs (1 hunks)
  • Maple2.Server.Game/Model/Field/Actor/FieldNpc.cs (1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
Maple2.Server.Game/Model/Field/Actor/FieldNpc.cs (3)
Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementState.cs (2)
  • MovementState (12-311)
  • MovementState (38-50)
Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateTasks/MovementState.EmoteTask.cs (1)
  • MovementState (7-53)
Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateTasks/MovementState.StandbyTask.cs (1)
  • MovementState (7-33)
Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateTasks/MovementState.EmoteTask.cs (2)
Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementState.cs (1)
  • SetState (123-129)
Maple2.Server.Game/Trigger/TriggerContext.Player.cs (1)
  • SetState (203-210)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: format
  • GitHub Check: build
🔇 Additional comments (4)
Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementStateTasks/MovementState.EmoteTask.cs (1)

51-51: Logic corrected to properly handle idle state.

The change now correctly sets the actor's state to ActorState.Idle when isIdle is true, which aligns with the expected behavior based on the parameter name. Previously, the logic was reversed, causing inconsistent state transitions.

Maple2.Server.Game/Model/Field/Actor/ActorStateComponent/MovementState.cs (2)

182-186: Added idle state handling to KeyframeEvent.

The addition of ActorState.Idle to the case statement ensures that keyframe events are properly processed when an actor is in the idle state, just as they are for emotion states. This improves the state handling completeness.


228-232: Added idle state handling to Update method.

Similar to the keyframe events, the Update method now correctly processes the idle state by calling EmoteStateUpdate. This completes the idle state integration with the animation control flow and ensures consistent behavior.

Maple2.Server.Game/Model/Field/Actor/FieldNpc.cs (1)

314-316:

Details

✅ Verification successful

Improved dynamic idle state detection.

Rather than using a hardcoded false value, the code now dynamically determines if an animation is idle by checking if the sequence name contains "idle" (case-insensitive). This is a more flexible approach that allows for proper state transitions based on the actual animation content.


🏁 Script executed:

#!/bin/bash
# Verify if there are any animation sequences with "idle" in their name
# that should NOT be treated as idle animations or vice versa

# Search for animation sequence declarations
rg -A 3 -B 3 "new AnimationSequence\\(" --type=cs

Length of output: 1918


Dynamic idle detection logic verified and approved.

The updated implementation correctly flags an idle animation by checking if the sequence name contains "idle" (case-insensitive). Our review of the related animation sequence declarations confirms that animations such as "Idle_A" are handled appropriately without any false positives. This dynamic approach is indeed more flexible than using a hardcoded value.

  • The use of StringComparison.OrdinalIgnoreCase ensures case-insensitive matching.
  • The presence of animations like "Idle_A" in the codebase (as seen in the search results) validates that the detection logic aligns with naming conventions.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

}

idleTask = MovementState.TryEmote(sequence.Name, false, duration);
bool isIdle = sequenceName.Contains("idle", StringComparison.OrdinalIgnoreCase);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little on the fence about blanket calling animations with idle in the name an idle task, behavior-wise, but it is worth a shot. If it breaks anything we can take a closer look when we discover it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants